package com.mfl.controller.admin;

import com.mfl.common.PageResult;
import com.mfl.common.Result;
import com.mfl.mapper.PostMapper;
import com.mfl.pojo.dto.NoticeDTO;
import com.mfl.pojo.dto.NoticePageQueryDTO;
import com.mfl.pojo.vo.NoticePageQueryVO;
import com.mfl.pojo.vo.NoticeVO;
import com.mfl.service.NoticeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

@RestController("adminNoticeController")
@RequestMapping("/cky/admin/notice")
@Slf4j
public class NoticeController implements Serializable {

    @Autowired
    private NoticeService noticeService;

    /**
     * 分页查询公告
     * @param noticePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(NoticePageQueryDTO noticePageQueryDTO){
        log.info("分页查询公告：{}", noticePageQueryDTO);
        PageResult pageResult = noticeService.pageQuery(noticePageQueryDTO);
        return Result.success("", pageResult);
    }

    /**
     * 新增公告
     * @param noticeDTO
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody NoticeDTO noticeDTO){
        log.info("新增公告：{}", noticeDTO);
        noticeService.insert(noticeDTO);
        return Result.success("新增成功");
    }

    /**
     * 批量删除公告
     * @param ids
     * @return
     */
    @DeleteMapping("/batchDelete")
    public Result batchDelete(@RequestParam List<Integer> ids){
        log.info("批量删除公告：{}", ids);
        noticeService.batchDelete(ids);
        return Result.success("删除成功");
    }

    /**
     * 修改公告状态
     * @param id
     * @return
     */
    @PutMapping("/status/{id}")
    public Result updateStatus(@PathVariable int id){
        log.info("修改公告状态：id：{}", id);
        noticeService.updateStatus(id);
        return Result.success("修改成功");
    }

    /**
     * 根据id查询公告
     * @param id
     * @return
     */
    @GetMapping("/getNoticeById")
    public Result<NoticeVO> getNoticeById(int id){
        log.info("查询公告：{}", id);
        NoticeVO noticeVO = noticeService.getNoticeById(id);
        return Result.success("", noticeVO);
    }

    /**
     * 修改公告
     * @param noticeDTO
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody NoticeDTO noticeDTO){
        log.info("修改公告：{}", noticeDTO);
        noticeService.update(noticeDTO);
        return Result.success("修改成功");
    }
}
